<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>05.form_fields | KnockOut</title>
  <script src="../assets/knockout-3.5.1.js"></script>
</head>
<body>

  <select size=3 data-bind="
    options: myItems,
    optionsText: 'name',
    optionsValue: 'id',
    optionsAfterRender: setOptionDisable">
  </select>
 
  <script type="text/javascript">
    var vm = {
      myItems: [
        { name: 'Item 1', id: 1, disable: ko.observable(false)},
        { name: 'Item 3', id: 3, disable: ko.observable(true)},
        { name: 'Item 4', id: 4, disable: ko.observable(false)}
      ],
      setOptionDisable: function(option, item) {
        ko.applyBindingsToNode(option, {disable: item.disable}, item);
      }
    };

    ko.applyBindings(vm);
  </script>

</body>
</html>